[#ftl]
[#--
 [@define "agile.dijit.PopupMenuItem" "agile.dijit.MenuItem"]
	category:"PopupMenuItem Component"
	,widgetName:"PopupMenuItem"
	,attributes:agile.delegate(agile.dijit.MenuItem.prototype.attributes,{
		label:lang.mixin({},agile.TextMetadata,{
			label:"i18n_label"
			,renderAsInnerHtml:true
			,onValueChange:function(/*widget*/widget,/*String*/name,/*Object*/value){					
//					widget.metadata(name,value);
				widget.metadata(this.metadataCategory+"."+name,value);
				widget.label.set("value",value);					
			}
			,toHtml:function(value){
				return "<span>"+value+"</span>";
			}
		})
		,iconClass:lang.mixin({},agile.TextMetadata,{
			_hidden:true,_ignore:true
		})			
		,accelKey:lang.mixin({},agile.TextMetadata,{
			label:"i18n_accel_key"
			,onValueChange:function(/*widget*/widget,/*String*/name,/*Object*/value){				
//					widget.metadata(name,value);	
				widget.metadata(this.metadataCategory+"."+name,value);
				widget.accelKey.set("value",value);
			}
		})								
	})
	
	,init:function(){
		domClass.add(this.domNode,"agilePopupMenuItem");
		query(">.agileMenu",this.containerNode).forEach(function(node){
			this.popupMenu = registry.byNode(node);
		},this);
		//create the default popup menu
		if(this.popupMenu == null){			
			this.popupMenu = new agile.dijit.Menu({parameters:{moveable:false,anchorNode:this.domNode,anchorPosition:"left"}});
			this.popupMenu.startup();
		}
		style.set(this.arrowWrapper,"visibility","visible");
		//show the popup menu when arrow is clicked	
		aspect.after(this.arrowWrapper,"onclick",lang.hitch(this,function(){
			//console.log(this.declaredClass,"agile.dijit.PopupMenuItem:onclick() is called");
			this.popupMenu.display();
		}));
		
		//show all descendants when double click
		aspect.after(this.arrowWrapper,"ondblclick",lang.hitch(this,function(){	
			//console.log(this.declaredClass,"agile.dijit.PopupMenuItem:ondblclick() is called");
			this.popupMenu.display(true,true);
		}));
		aspect.after(this.label,"onMouseEnter",lang.hitch(this,function(){				
			this.popupMenu.display(true);
		}));
		
		var arrowWrapperId = this.id+"ArrowWrapper";
		attr.set(this.arrowWrapper,"id",arrowWrapperId);
		if(agile.dijit.PopupMenuItem.prototype.arrowTooltip == null){
			agile.dijit.PopupMenuItem.prototype.arrowTooltip = new dijit.Tooltip({label: "Click to show/hide children <br> Double Click to show all descendants"});
		}
		agile.dijit.PopupMenuItem.prototype.arrowTooltip.addTarget(arrowWrapperId);
		
		//console.log(this.declaredClass,"agile.dijit.PopupMenuItem:startup() is called",this.id);
	}
	
	,getTemplateParameters:function(params){
		var parameters = this.inherited("getTemplateParameters",arguments);
		parameters.label = this.metadata("parameters.label");
		
		////console.log(this.declaredClass,"agile.dijit.PopupMenuItem:getTemplateParameters() is called");
		return parameters;
	}
	,getInnerWidgetTemplate:function(params){
		var template = this.popupMenu.toHtml(params);
		return template;
	}
[/@]
--]
